﻿@using AdverseEventReportSystem.Model
@{
    var mode = ViewBag.AdverseEventMode as AdverseEventMode;
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    <link href="~/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <link href="~/lib/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    <link href="~/lib/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/css/common.css" rel="stylesheet" type="text/css" />
    <script src="~/lib/jquery/jquery-1.9.0.min.js" type="text/javascript"></script>
    <script src="~/lib/ligerUI/js/ligerui.all.js"></script>
    <script src="~/Scripts/common.js"></script>
    <style>
        input[type="radio"] {
            vertical-align: middle;
            margin-top: -2px;
            margin-bottom: 1px;
            margin-right: 5px;
        }
    </style>
    <script>
        $(function () {
            placeholder();

            if ($("#hdnTypeId").val() == 0) {
                $("#hdnTypeId").val(frameElement.dialog.get('data').typeID);
            }

            $(":radio").click(function(){
                if($(this).val()<=1){
                    $("#trOptions").show();
                }
                else
                {
                    $("#trOptions").hide();
                }
            });
            $(":radio[name='inputType'][value='" + @(mode.InputType) + "']").prop("checked", "checked").click();
            $("#txtOptions").val('@(mode.Options)');
        });

        function save() {
            var id = $("#hdnModeId").val();
            var typeId = $("#hdnTypeId").val();
            var modeName = $("#txtModeName").val();
            var inputType = $('input[name="inputType"]:checked').val()
            var options = $("#txtOptions").val();
            var sort = $("#txtSort").val();

            if (IsEmpty(modeName)) {
                $.ligerDialog.error("方式名称不能为空");
                $("#txtModeName").focus();
                return;
            }
            if (inputType>1)
            {
                options = "";
            }
            var dialog = frameElement.dialog;
            $.ajax({
                url: "/AdverseEventMode/Save",
                type: "post",
                data: {
                    ID: id,
                    TypeID: typeId,
                    ModeName: modeName,
                    InputType: inputType,
                    Options:options,
                    Sort: sort
                },
                success: function (r) {
                    var r = $.parseJSON(r);
                    if (r.Result == 1) {
                        parent.$(".l-dialog-btn-inner").click();
                        dialog.close();
                    }
                    else if (r.Result == 0) {
                        $.ligerDialog.error(r.Body);
                    }
                    else {
                        $.ligerDialog.error("程序错误");
                    }
                }
            });
        }
        function closeDialog() {
            frameElement.dialog.close();//关闭dialog
        }
    </script>
</head>
<body>
    <div style="margin:10px 0px;">
        <table style="width:100%;">
            <tr>
                <td style="text-align:right; width:80px; height: 30px;line-height: 30px;">
                    方式名称：
                </td>
                <td>
                    <input type="text" id="txtModeName" class="l-text" maxlength="50" style="width:300px;" value="@(mode.ModeName)" /><font style="color:red;">&nbsp;*</font>
                </td>
            </tr>
            <tr>
                <td style="text-align:right; width:80px; height: 30px;line-height: 30px;">
                    填写类型：
                </td>
                <td style="padding-top: 5px;">
                    <label for="inputType1">
                        <input type="radio" id="inputType1" name="inputType" value="0" checked />&nbsp;单选
                    </label>&nbsp;&nbsp;
                    <label for="inputType2">
                        <input type="radio" id="inputType2" name="inputType" value="1" />&nbsp;多选
                    </label>&nbsp;&nbsp;
                    <label for="inputType3">
                        <input type="radio" id="inputType3" name="inputType" value="2" />&nbsp;文本框
                    </label>&nbsp;&nbsp;
                    <label for="inputType4">
                        <input type="radio" id="inputType4" name="inputType" value="3" />&nbsp;时间控件
                    </label>
                </td>
            </tr>
            <tr id="trOptions">
                <td style="text-align:right; width:80px; height: 30px;line-height: 30px; vertical-align:top;">
                    选项：
                </td>
                <td style="padding-top: 5px;">
                    <textarea id="txtOptions" rows="8" class="l-textarea ipt" maxlength="500" style="width:290px;padding:5px;" datavalue="多个选项用#隔开 例如：有#无"></textarea>
                </td>
            </tr>
            <tr>
                <td style="text-align:right; width:80px; height: 30px;line-height: 30px;">
                    排序：
                </td>
                <td style="padding-top: 5px;">
                    <input type="text" id="txtSort" class="l-text" maxlength="10" style="width:300px;" value="@(mode.Sort)" />
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align:center;padding-top:10px;">
                    <input id="btnSubmit" type="button" value="确定" class="l-button" onclick="save()" />&nbsp;&nbsp;&nbsp;
                    <input id="btnCancel" type="button" value="取消" class="l-button-cancel" onclick="closeDialog()" />
                </td>
            </tr>
        </table>
        <input type="hidden" id="hdnModeId" value="@(mode.ID)" />
        <input type="hidden" id="hdnTypeId" value="@(mode.TypeID)" />
    </div>
</body>
</html>
